package com.flida.echart.basic.service;

import com.flida.echart.basic.api.service.GateUserRoleService;
import com.flida.echart.basic.api.system.entity.SysMenuEntity;
import com.flida.echart.basic.api.system.entity.SysRoleEntity;
import com.flida.echart.basic.system.service.SysMenuService;
import com.flida.echart.basic.system.service.SysRoleMenuService;
import com.flida.echart.basic.system.service.SysRoleService;
import com.flida.echart.basic.system.service.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by yzc on 2016/12/18.
 */
@Service("gateUserRoleService")
public class GateUserRoleServiceImpl implements GateUserRoleService {

    @Autowired
    public SysRoleService sysRoleService;
    @Autowired
    public SysRoleMenuService sysRoleMenuService;
    @Autowired
    public SysUserRoleService sysUserRoleService;
    @Autowired
    public SysMenuService sysMenuService;


    /**
     * userole相關操作
     *
     * @param userId
     * @param roleIdList
     **/
    public void saveOrUpdateUserRole(Long userId, List<Long> roleIdList) {
        sysUserRoleService.saveOrUpdate(userId,roleIdList);
    }

    /**
     * 根据用户ID，获取角色ID列表
     *
     * @param userId
     */
    public List<Long> queryRoleIdList(Long userId) {
        return sysUserRoleService.queryRoleIdList(userId);

    }

    /**
     * 根据用户ID，刪除用戶角色（中间表）
     *
     * @param userId
     */
    public void deleteUserRole(Long userId) {
         sysUserRoleService.delete(userId);
    }

    /**
     * 根据角色id查询角色
     *
     * @param roleId
     */
    public SysRoleEntity queryObjectRole(Long roleId) {
        return sysRoleService.queryObject(roleId);
    }

    /**
     * 查询角色
     *
     * @param map
     */
    public List<SysRoleEntity> queryListRole(Map<String, Object> map) {
        return sysRoleService.queryList(map);
    }

    /**
     * 查询角色 条数
     *
     * @param map
     */
    public int queryTotalRole(Map<String, Object> map) {
        return sysRoleService.queryTotal(map);
    }

    /**
     * 保持角色
     *
     * @param role
     */
    public void saveRole(SysRoleEntity role) {
        sysRoleService.save(role);
    }

    /**
     * 修改角色
     *
     * @param role
     */
    public void updateRole(SysRoleEntity role) {
        sysRoleService.update(role);
    }

    /**
     * 删除角色
     *
     * @param roleIds
     */
    public void deleteBatchRole(Long[] roleIds) {
        sysRoleService.deleteBatch(roleIds);
    }

    /**
     * 角色菜单相关
     *
     * @param roleId
     * @param menuIdList
     **/
    public void saveOrUpdateRoleMenu(Long roleId, List<Long> menuIdList) {
        sysRoleMenuService.saveOrUpdate(roleId,menuIdList);
    }

    /**
     * 根据角色ID，获取菜单ID列表
     *
     * @param roleId
     */
    public List<Long> queryMenuIdListRoleMenu(Long roleId) {
        return sysRoleMenuService.queryMenuIdList(roleId);
    }

    /**
     * 根据父菜单，查询子菜单
     *
     * @param parentId   父菜单ID
     * @param menuIdList 用户菜单ID
     */
    public List<SysMenuEntity> queryListParentId(Long parentId, List<Long> menuIdList) {
        return sysMenuService.queryListParentId(parentId,menuIdList);
    }

    /**
     * 获取不包含按钮的菜单列表
     */
    public List<SysMenuEntity> queryNotButtonList() {
        return sysMenuService.queryNotButtonList();
    }

    /**
     * 获取用户菜单列表
     *
     * @param userId
     */
    public List<SysMenuEntity> getUserMenuList(Long userId) {
        return sysMenuService.getUserMenuList(userId);
    }

    /**
     * 查询菜单
     *
     * @param menuId
     */
    public SysMenuEntity queryObjectMenu(Long menuId) {
        return sysMenuService.queryObject(menuId);
    }

    /**
     * 查询菜单列表
     *
     * @param map
     */
    public List<SysMenuEntity> queryListMenu(Map<String, Object> map) {
        return sysMenuService.queryList(map);
    }

    /**
     * 查询总数
     *
     * @param map
     */
    public int queryTotalMenu(Map<String, Object> map) {
        return sysMenuService.queryTotal(map);
    }

    /**
     * 保存菜单
     *
     * @param menu
     */
    public void saveMenu(SysMenuEntity menu) {
        sysMenuService.save(menu);
    }

    /**
     * 修改
     *
     * @param menu
     */
    public void updateMenu(SysMenuEntity menu) {
        sysMenuService.update(menu);
    }

    /**
     * 删除
     *
     * @param menuIds
     */
    public void deleteBatchMenu(Long[] menuIds) {
        sysMenuService.deleteBatch(menuIds);
    }


}
